//
//  SinaHomeViewController.m
//  oc微博
//
//  Created by 安陆与 on 16/1/13.
//  Copyright © 2016年 安陆与. All rights reserved.
//

#import "SinaHomeViewController.h"
#import "SinaAccountViewModel.h"
#import "SinaStatusListViewModel.h"
#import "SinaStatusModel.h"
#import "SVProgressHUD.h"
#import "SinaStatusViewModel.h"
#import "SinaHomeTableViewCell.h"
#import "MJRefresh.h"

static NSString *SinaHomeCellReuseIdentifier = @"SinaHomeCellReuseIdentifier";

@interface SinaHomeViewController ()

@property (nonatomic, strong) SinaStatusListViewModel *viewModel;

@property (nonatomic, strong) NSArray *listMessage;
@end

@implementation SinaHomeViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (![[SinaAccountViewModel alloc]init].isLogin) {
        
    }else{
        
       self.viewModel = [[SinaStatusListViewModel alloc]init];
        
//        [self.viewModel getData];
        [SVProgressHUD show];
        [self.viewModel getData:^{
            
            self.listMessage = self.viewModel.list;
            
            [self.tableView reloadData];
            [SVProgressHUD dismiss];

            
            

        } failure:^{
            
            [SVProgressHUD dismiss];
        }];
        
        //如果没有xib 的时候一定要注册cell
        [self.tableView registerClass:[SinaHomeTableViewCell class]forCellReuseIdentifier:SinaHomeCellReuseIdentifier];
        
        self.tableView.estimatedRowHeight = 200;
        
        self.tableView.rowHeight = UITableViewAutomaticDimension;
        
    }
    
//    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        // 进入刷新状态后会自动调用这个block
//    }];
//    
//    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadNewData方法）
//    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
//    
//    // 马上进入刷新状态
//    [self.tableView.header beginRefreshing];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.listMessage.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    SinaHomeTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:SinaHomeCellReuseIdentifier forIndexPath:indexPath];
    
//    SinaStatusModel *model = self.viewModel.list[indexPath.row];
    SinaStatusViewModel *viewModel = self.listMessage[indexPath.row];
//    cell.textLabel.text = model.user.screen_name;
//    cell.textLabel.text = viewModel.model.user.screen_name;
    
    //用于测试
//    NSLog(@"%@",viewModel.reposts_string);
//    
//    NSLog(@"%@",viewModel.pic_urls);
    cell.model = viewModel;
    
    
    return cell;
    
}



@end
